package atom.core2.j2ee.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;


public class EncodingFilter extends HttpServlet implements Filter {
	private static final long serialVersionUID = 1L;
	private FilterConfig filterConfig;
    private String encodingChar; 	
	
	public void destroy() {
		super.destroy(); 
	}

    public void init(FilterConfig filterConfig) throws ServletException {
        this.encodingChar=filterConfig.getInitParameter("encodingChar");
        this.filterConfig = filterConfig;
    }	

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {
        try {
            request.setCharacterEncoding(this.encodingChar);
            filterChain.doFilter(request, response);

        } catch (ServletException sx) {
            filterConfig.getServletContext().log(sx.getMessage());
        } catch (IOException iox) {
            filterConfig.getServletContext().log(iox.getMessage());
        }
        catch(Exception e)
        {
        	//DatabaseManager.rollbackTransaction();
        	e.printStackTrace();
        	//System.out.println("-------------EncodingFilter Exception");
        }
    }    
}
